#ifndef __AT_DEVICE_M5310A_H__
#define __AT_DEVICE_M5310A_H__

#include <rtconfig.h>
#ifdef BSP_USING_M5311 /* BSP_USING_M5311 */

#include <rtdef.h>
#include "at.h"
#include "at_device_m5311_cfg.h"

typedef enum
{
    NBMODULE_RST,                     //NB RST
    NBMODULE_POWERON,                 //NB����

    NBMODULE_DISABLE_ECHO,            //ʧ�ܻ���
    NBMODULE_SET_ERROR,               //ʹ�ܱ���
    NBMODULE_EN_NET_REG_STATUS,       //ʹ������״̬�ϱ�
    NBMODULE_QUERY_IMEI,              //��ѯIMEI
    NBMODULE_SET_BAND,                //����Ƶ�Σ��ƶ���ͨ8����5��
    NBMODULE_SET_PSM,                 //����PSMģʽ����
    NBMODULE_SET_EDRX,                //����eDRXģʽ����
    NBMODULE_QUERY_CSQ,               //��ѯ�ź�
    NBMODULE_QUERY_PDP_ADRR,          //��ѯPDP��ַ
    NBMODULE_CREATE_DEVICE,           //�����豸
    NBMODULE_REG_DEVICE,              //ע���豸
    NBMODULE_UPDATE_DEVICE_STATUS,    //���������豸״̬
    NBMODULE_DEVICE_MSG_CONFIG,       //������Ϣ��ʽ hex
//    NBMODULE_EN_MSG_,    //ʹ������Ϣ�����ϱ�
    NBMODULE_QUERY_CARD_ID,           //��ѯsim��id
    NBMODULE_QUERY_IMSI,              //��ѯ�����ƶ��û�ʶ����
    NBMODULE_QUERY_TIME,              //��ѯ��ǰʱ��
    NBMODULE_EN_SIGN_STATUS_REBACK,   //ʹ���ź�����״̬��������
    NBMODULE_EN_SLEEP_INDICATION,     //ʹ��������˯��ָʾ
    NBMODULE_EN_WAKEUP_INDICATION,    //ʹ�ܴ����˯�߻���ָʾ
    NBMODULE_EN_SLEEP,                //����ʹ��˯��
    NBMODULE_SEND_DATA,               //��������
    NBMODULE_ENTER_SLEEP,             //�������˯��
    NBMODULE_WAKEUP,                  //���˯�߻���
    
    NBMODULE_QUERY_NET_STATUS,        //��ѯ����״̬
}AT_NBMODULE_CMD;

typedef enum
{
  NBMODULE_EOK = 0,
  NBMODULE_ERROR,
  NBMODULE_CSQ_ERROR,
  NBMODULE_SIM_ERROR,
  NBMODULE_NO_NET,
}NB_ERROR;

typedef struct
{
  unsigned char *dat;
  unsigned short len;
}NB_MSG;

typedef struct{
  uint8_t imei[15 + 1];
  uint8_t iccid[20 + 1];
  uint8_t imsi[15 + 1];
  uint8_t ip[15 + 1];
  uint8_t csq;
  uint8_t sign_mode : 1;
  uint8_t net_status : 1; //ʵ�����ӵ�ƽ̨
}nb_info_t;

struct rt_nb_device
{
  struct rt_device parent;
  at_response_t resp;
  nb_info_t info;
  NB_MSG nb_msg;
  void  *data;
};

#define NBMOUDLE_EVT_NET_REG              (1 << 0)
#define NBMOUDLE_EVT_REG_SUCCESS          (1 << 1)
#define NBMOUDLE_EVT_UPDATE_SUCCESS       (1 << 2)
#define NBMOUDLE_EVT_OBSERVE_SUCCESS      (1 << 3)


#define NBMODULE_DEFAULT_TIMEOUT					300   //Ĭ�ϳ�ʱʱ��
#define NBMODULE_SEND_DATA_TIMEOUT				500	  //Ĭ�Ϸ������ݳ�ʱʱ��
#define NBMODULE_CPSMS_TIMEOUT				    1000  //CPSMS��ʱʱ�䣨ʵ�ʲ�����ӵģ�
#define NBMODULE_NPTWEDRXS_TIMEOUT				1000  //NPTWEDRXS��ʱʱ��
#define NBMODULE_CGATT_TIMEOUT						1000  //CGATT��ʱʱ��
#define NBMODULE_CGACT_TIMEOUT						1000  //CGACT��ʱʱ��
#define NBMODULE_CFUN_TIMEOUT							15000	//CFUN��ʱʱ��

#define NBMODULE_SEND_LEN(x)              (2 * x + 9 + 5 + 1)

#endif /* BSP_USING_M5311 */

#endif
